<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * Banner接口
 * @ApiWeigh (89)
 */
class Banner extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    /**
     * 获取Banner列表
     * 
     * @ApiTitle    (获取Banner列表)
     * @ApiSummary  (根据类型获取Banner列表)
     * @ApiMethod   (GET)
     * @ApiParams   (name="type", type="string", required=true, description="类型:travel=文旅,video=视频")
     * @ApiReturn   ({
        "code": 1,
        "msg": "success",
        "data": [{
          "id": 1,
          "title": "标题",
          "image": "图片地址",
          "type": "travel",
          "link_id": 1
        }]
      })
     */
    public function index()
    {
        $type = $this->request->get('type');
        
        if (!in_array($type, ['travel', 'video'])) {
            $this->error('参数错误');
        }
        
        $list = \app\common\model\Banner::where([
            'type' => $type,
            'status' => 1
        ])->order('weigh DESC,id DESC')->select();
        
        // 处理图片完整路径
        foreach ($list as &$item) {
            $item['image'] = cdnurl($item['image'],true);
        }
        
        $this->success('', $list);
    }
}